//给一个数N，需要多少步能变成Fbonacci数，每步只能+1或-1
#include<iostream>
#include<stack>
using namespace std;
int main()
{
    int N=0; 
    int fb=0;
    cin >> N;
    stack<int> one,two;
    one.push(0);//0 1 3 8 21
    two.push(1);//1 2 5 13
    while(N>one.top()&&N>two.top())
    {
        fb=one.top()+two.top();
        one.push(fb);
        swap(one,two);
    }
    int a=abs(N-one.top());
    int b=abs(N-two.top());
    cout <<(a<b?a:b);
    return 0;
}